<?php
loadTemp("admin/models/class/classheader.php");
?>
<script type="text/javascript">
$(document).ready(function(){
	loadAdminTopItem();
	activeAdminTopItem("s_c_teacherclass");
});
</script>
<?php checkAdminPermission("admin.class.teacher_class","admin.class.*");?>
<!-- Start -->
<script type="text/javascript">
$(document).ready(function(){
	$("#teacherlist_temple").hide();
	$("#form_teacher_search").hide();
	$("#s_a_t_classinfo").hide();
	bindAjaxForm($("#form_class_search"),s_teacherclass_onSuccess,s_teacherclass_onError,"admin_di");
	bindAjaxForm($("#form_teacher_search"),s_teacherclass_onSuccess,s_teacherclass_onError,"admin_di");
});
function s_teacherclass_onSuccess(data){
	s_teacherclass_operatedone(data.code,data.message,data.data);
}
function s_teacherclass_onError(data){
	console.log(data);
	s_teacherclass_operatedone(-101,"服务器返回了未知的数据，请上报管理员",data.responseText);

}
function s_teacherclass_operatedone(id,message,data){
	if(id==-101){
		showMessage("s_teacherclass_message",-101,message+"<br><br><pre>"+data+"</pre>");
		return;
	}
	if(id!=0&&id!=3){
		showMessage("s_teacherclass_message",id,message);
	}
	if(id==0){
		showMessage("s_teacherclass_message",id,message);
	}
	if(data.op=="search_teacher_class"){
		$("#form_teacher_search").show();
		$(".s_classid").html(data.classdata.classid);
		$(".s_value_classid").attr("value",data.classdata.classid);
		$(".s_classname").html(data.classdata.displayname);
		$(".s_class_introduce").html(data.classdata.description);
		$("#s_a_t_classinfo").show();
		$("#form_class_search").hide();
		$.each(data.teacher,function(k,v){
			addTeacher(v);
		});
	}
	if(data.op=="showTeacherSelecter"){
		$("#form_class_search").hide();
		$("#form_teacher_search").show();
		showMessage("s_teacherclass_message",id,message);
	}
	if(data.op=="removeList"){
		$("#s_a_t_teach_"+data.uid).remove();
	}
	if(data.op=="addTeacher"){
		showMessage("s_teacherclass_message",id,message);
		addTeacher(data);
	}
}
function addTeacher(data){
	var $tmp = $("#teacherlist_temple").clone();
	$tmp.show();
	$tmp.attr("id","s_a_t_teach_"+data.uid);
	$tmp.find(".s_a_t_name").html(data.card.name).attr("href",getHomeURL(data.card.uid));
	$tmp.find(".s_a_t_subject").html(data.subject);
	$tmp.find(".s_a_t_classid").attr("classid",data.classid);
	$tmp.find(".s_a_t_uid").attr("uid",data.card.uid);
	$tmp.find(".s_a_t_head").attr("src",data.card.head_image_path);
	$tmp.find(".s_a_t_subject").html(data.displayname);
	$("#s_a_t_teacher_list").append($tmp);
}
function s_a_t_removeTeacher(e){
	$uid = e.attr("uid");
	$classid = e.attr("classid");
	ajaxRequest("uid="+$uid+"&classid="+$classid,"admin.php?mod=class&ajax=true&op=remove_teacher",s_teacherclass_onSuccess,s_teacherclass_onError);
}
</script>
<div class="s_admin_in_container">
	<h2 class="ui dividing header">班级教师管理</h2>
	<div class="ui message">
		<div class="header">小提示</div>
		<ul class="list">
			<li>这里是班级教室管理模块</li>
			<li>你可以在这里增加/删除班级的教师</li>
		</ul>
	</div>
	<div class="ui message hidden" id="s_teacherclass_message"></div>
	<table class="ui unstackable table" id="s_a_t_classinfo">
		<thead>
			<tr>
				<th>班级信息栏</th>
				<th></th>
			</tr>
		</thead>
		<tbody>
			<tr>
				<td>班级id</td>
				<td class="s_classid">empty</td>
			</tr>
			<tr>
				<td>班级名称</td>
				<td class="s_classname">empty</td>
			</tr>
			<tr>
				<td>班级介绍</td>
				<td class="s_class_introduce">empty</td>
			</tr>
		</tbody>
	</table>
	<h4 class="ui dividing header">教师列表</h4>
	<form class="ui form" url="admin.php?mod=class&ajax=true&op=search_teacher_class" id="form_class_search">
		<div class="ui action fluid input">
			<div class="ui left icon input">
				<input type="text" name="classid" placeholder="请输入你要编辑的班级的班级id" id="s_class_search">
				<i class="users icon"></i>
			</div>
			<button class="ui button submit" type="submit">确定</button>
		</div>
	</form>
	<div class="item" id="teacherlist_temple">
		<div class="right floated content">
			<a class="lm_item s_a_t_uid s_a_t_classid" onClick="s_a_t_removeTeacher($(this));">删除</a>
		</div>
		<img class="ui avatar image s_a_t_head" src="">
		<div class="content s_a_t_description">
			<a class="s_a_t_name"></a>
			<div class="lm_item s_a_t_subject"></div>
		</div>
	</div>
	<div class="ui middle relaxed aligned divided list" id="s_a_t_teacher_list"></div>
	<form class="ui form" url="admin.php?mod=class&ajax=true&op=add_teacher" id="form_teacher_search">
		<h4 class="ui dividing header">添加教师</h4>
		<input class="s_value_classid" type="hidden" name="classid" value="">
		<div class="ui action fluid input">
			<div class="ui left icon input">
				<input type="text" name="account" placeholder="请输入你要添加的教师账号" id="s_teacher_search">
				<i class="users icon"></i>
			</div>
			<button class="ui button submit" type="submit">确定</button>
		</div>
	</form>
</div>
